/**
 * Created by mar105 on 2019-02-13.
 */
/* eslint-disable no-undef,import/first,prefer-destructuring,jsx-a11y/alt-text */
import React, {Component} from 'react';
import {Table, Form, Input, Button, Upload, Icon, Modal} from 'antd';
import styles from '../../index.less';
import * as commonUtils from '../../utils/utils';
import ShowTypeNew from '../Common/CommonComponent';
import Highlighter from 'react-highlight-words';
import * as commonConfig from '../../utils/config';

const FormItem = Form.Item;

export default class CommonTable extends Component {
  /**   构造函数   */
  constructor(props) {
    super(props);
    this.state = {
      previewVisible: false, /* 图片预览弹窗 */
      previewImage: '', /* 预览图片地址 */
      headerColumn: [], /*   表头信息(数据类型:数组对象)   */
      selectedRowKeys: [], /*   已选择的数据行(数据格式:数组)   */
      dataSource: [], /*   数据(数据格式:数组对象)   */
      totalData: [], /* 总计数据 */
      enabled: false, /* 是否为编辑 */
      filteredValue: [], /* 过滤数据值 */
    };
    this.rowKey = commonUtils.isNotEmptyObject(props.tableProps) && !commonUtils.isEmpty(props.tableProps.rowKey) ? props.tableProps.rowKey : 'sId'; /*   表格主键  */
    this.config = {}; /*   配置信息(基础)(数据格式:对象)   */
    this.headerColumn = []; /*   表头信息(数据类型:数组对象)   */
    this.tableColumn = []; /*   table的表头信息(数据类型:数组对象)   */
    this.tableTotalColumn = []; /*   table的表头信息(数据类型:数组对象)   */
    this.scrollX = 0; /*   表格宽度统计值(数据格式:整形)   */
    this.formId = ''; /*   窗体Id(数据格式:字符串)   */
    this.sId = ''; /*   表格Id(数据格式:字符串)   */
    this.isUploadShow = false; /*   是否显示上传控件(数据格式:布尔)   */
    this.isLookShow = false; /*   是否显示查看控件(数据格式:布尔)   */
    this.isAddShow = false; /*   是否显示添加控件(数据格式:布尔)   */
    this.isDelShow = false; /*   是否显示删除控件(数据格式:布尔)   */
    // this.onUploadChange = () => {}; /*   上传后执行函数(数据格式:函数)   */
  }

  /**   渲染前只执行一次   */
  componentWillMount() {
    /*   state和this属性赋值   */
    this.assignmentWillProps(this.props);
  }

  /**   props改变的时候触发   */
  componentWillReceiveProps(nextProps) {
    /*   state和this属性赋值   */
    this.assignmentWillProps(nextProps);
  }

  /**   返回true执行渲染,返回false不渲染   */
  shouldComponentUpdate(nextProps, nextState) {
    const {
      headerColumn, dataSource, totalData, selectedRowKeys, enabled, filteredValue, previewVisible, previewImage,
    } = this.state;
    return enabled !== nextState.enabled ||
      JSON.stringify(headerColumn) !== JSON.stringify(nextState.headerColumn) ||
      JSON.stringify(dataSource) !== JSON.stringify(nextState.dataSource) ||
      JSON.stringify(totalData) !== JSON.stringify(nextState.totalData) ||
      JSON.stringify(selectedRowKeys) !== JSON.stringify(nextState.selectedRowKeys) ||
      JSON.stringify(previewVisible) !== JSON.stringify(nextState.previewVisible) ||
      JSON.stringify(previewImage) !== JSON.stringify(nextState.previewImage) ||
      JSON.stringify(this.props.tableProps.pagination) !== JSON.stringify(nextProps.tableProps.pagination) ||
      JSON.stringify(filteredValue) !== JSON.stringify(nextState.filteredValue);
  }

  componentDidUpdate() {
    this.handleTotalScroll();
  }

  /**   行选择   */
  onRowClick = (record) => {
    this.handleSelectRowChange([record[this.rowKey]]);
  };

  /**   行选择   */
  onDoubleClick = (record) => {
    if (this.props.onDoubleClick !== undefined) {
      this.props.onDoubleClick(record);
    }
  };

  /**   获取复选框对象的props   */
  getRowSelection = () => {
    return {
      selectedRowKeys: this.state.selectedRowKeys, /*   已选择的数据集   */
      onChange: this.handleSelectRowChange, /*   选择行发生改变时调用的函数   */
      getCheckboxProps: record => ({
        style: record.bSum ? {display: 'none'} : {display: 'checkbox'},
      }), /*   过滤合计的选择框   */
      type: this.props.rowSelectionType, /* checkbox or radio */
    };
  };

  /**   获取table对象的props   */
  getTableProps = () => {
    /*   给数据都添加上key   */
    const {dataSource} = this.state;
    /*   返回值   */
    return {
      rowKey: this.rowKey,
      size: 'middle',
      bordered: true, /*   显示边框   */
      className: !this.props.enabled ? styles.disabledProup : styles.proup, /*   样式控制   */
      scroll: {x: this.scrollX, y: 'calc(100vh - 438px)'}, /*   宽度   */
      dataSource, /*   数据   */
      columns: this.tableColumn, /*   表头   */
      rowSelection: this.getRowSelection(), /*   添加的复选框(checkbox)功能   */
      pagination: false, /*   不分页   */
      onRow: (record) => {
        return {
          onClick: () => {
            this.onRowClick(record);
          }, onDoubleClick: () => {
            this.onDoubleClick(record);
          }
        };
      },
      // onChange: this.onChange,
      id: commonUtils.isEmptyArr(dataSource) ?
        'unDataBox' :
        'dataBox', /*   用户修改antd table中自带的样式(我听别人说的要这么弄,你们别骂我)   */
      ...this.props.tableProps,
    };
  };

  /**   获取table对象的props   */
  getTableTotalProps = () => {
    /*   给数据都添加上key   */
    const {totalData} = this.state;
    /*   返回值   */
    return {
      size: 'middle',
      bordered: true, /*   显示边框   */
      className: commonUtils.isEmpty(this.props.className) ? !this.props.enabled ? styles.disabledProup : styles.proup : this.props.className, /*   样式控制   */
      scroll: {x: this.scrollX}, /*   宽度   */
      dataSource: totalData, /*   数据   */
      columns: this.tableTotalColumn, /*   表头   */
      rowSelection: commonUtils.isEmpty(this.props.rowSelection) ? this.getRowSelection() : this.props.rowSelection, /*   添加的复选框(checkbox)功能   */
      pagination: false, /*   不分页   */
      id: commonUtils.isEmptyArr(totalData) ?
        'unTotalDataBox' :
        'dataBox',
    };
  };

  /**   获取showConfig   */
  getShowConfig = (sName) => {
    /*   返回值声明   */
    let showConfig = [];
    /*   通过sName过滤出对应的showConfig   */
    const showConfigArr = this.props.config.gdsconfigformslave.filter(item => item.sName === sName && item.bVisible);
    if (commonUtils.isNotEmptyArr(showConfigArr)) {
      showConfig = showConfigArr[0];
    }
    /*   返回值   */
    return showConfig;
  };

  /**   获取table的表头信息(主要是table中的表头信息合并,[{title:1-1},{title:1-2}]变成[{title:1,children:[{title:1},{title:2}]}]) type：是否过滤   */
  getTableColumn = (headerColumn, type, props) => {
    /*   返回值声明   */
    const tableColumn = [];
    let iIndex = 0;
    /*   遍历每一个表头标题   */
    for (const column of headerColumn) {
      /*   表头标题   */
      const title = column.title;
      /*   带'-'的表头是需要合并滴   */
      const index = title.indexOf('-');
      /*   合并走合并的,不合并就直接push   */
      let columnNew = {};
      let sorter;
      if (props.tableProps !== undefined && props.tableProps.rowKey !== 'sId') {
        sorter = true;
      } else {
        const firstDataIndex = column.dataIndex.substring(0, 1);
        if (firstDataIndex === 'd' || firstDataIndex === 'i') {
          sorter = (a, b) => (commonUtils.isEmpty(a[column.dataIndex]) ? 0 : a[column.dataIndex] - commonUtils.isEmpty(b[column.dataIndex]) ? 0 : b[column.dataIndex]);
        } else {
          sorter = (a, b) => (commonUtils.isEmpty(a[column.dataIndex]) ? 0 : a[column.dataIndex].length) - (commonUtils.isEmpty(b[column.dataIndex]) ? 0 : b[column.dataIndex].length);
        }
      }
      columnNew = {
        ...column,
        sorter,
        ...this.getColumnSearchProps(iIndex, column, type, props),
      };
      if (index > -1) { /*   合并   */
        this.mergeTableColumn(title, columnNew, tableColumn, index);
      } else { /*   不合并   */
        tableColumn.push(columnNew);
      }
      iIndex += 1;
    }
    /*   返回值   */
    return tableColumn;
  };

  getColumnSearchProps = (iIndex, column, type, props) => (
    this.props.onFilterData !== undefined && iIndex === 0 && type === 'filter' ? {
      onFilter: this.props.onFilterData.bind(this, props.name, column.dataIndex),
    } : column.dataIndex.substring(0, 1) !== 'b' && column.bFind && type === 'filter' && !props.enabled ? {
      filterDropdown: ({
                         setSelectedKeys, selectedKeys, confirm, clearFilters,
                       }) => (
        <div style={{padding: 8}}>
          <Input
            ref={(node) => {
              this.searchInput = node;
            }}
            placeholder={`Search ${column.title}`}
            value={selectedKeys[0]}
            onChange={e => setSelectedKeys(e.target.value ? [e.target.value] : [])}
            onPressEnter={() => this.handleSearch(selectedKeys, confirm)}
            style={{width: 188, marginBottom: 8, display: 'block'}}
          />
          <Button
            type="primary"
            onClick={() => this.handleSearch(selectedKeys, confirm)}
            icon="search"
            size="small"
            style={{width: 90, marginRight: 8}}
          >
            Search
          </Button>
          <Button
            onClick={() => this.handleReset(clearFilters)}
            size="small"
            style={{width: 90}}
          >
            Reset
          </Button>
        </div>
      ),
      filterIcon: filtered => <Icon type="search" style={{color: filtered ? '#1890ff' : undefined}}/>,
      onFilter: (value, record) => {
        if (record[column.dataIndex] !== undefined) {
          return record[column.dataIndex].toString().toLowerCase().includes(value.toLowerCase());
        } else {
          return ''.toString().toLowerCase().includes(value.toLowerCase());
        }
      },
      onFilterDropdownVisibleChange: (visible) => {
        if (visible) {
          setTimeout(() => this.searchInput.select());
        }
      },
      render: text => (
        <Highlighter
          highlightStyle={{backgroundColor: '#ffc069', padding: 0}}
          searchWords={[this.state.searchText]}
          autoEscape
          textToHighlight={commonUtils.isEmpty(text) ? '' : text.toString()}
        />
      ),
    } : {});

  /**   获取ShowType的props   */
  getShowTypeProps = (text, record, sName) => {
    /*   待用数据   */
    const showConfig = this.getShowConfig(sName); /*   配置信息   */
    /*   返回值   */
    return {
      name: this.props.name,
      sId: record.sId, /*   修改当前编号(数据格式:字符串)   */
      dataValue: text, /*   本showType数据(数据格式:对象)   */
      enabled: this.props.enabled && !showConfig.bReadonly, /*   是否是查看状态(数据格式:布尔)   */
      showConfig, /*   关于本showType相关配置(数据格式:对象)   */
      formId: this.formId, /*   窗体Id(数据格式:字符串)   */
      onChange: this.props.onDataChange, /*   表单数据改变事件方法(数据格式:函数)   */
      bTable: true, /*   是否为表格数据   */
      getSqlDropDownData: this.props.getSqlDropDownData,
      handleSqlDropDownNewRecord: this.props.handleSqlDropDownNewRecord,
      getFloatNum: this.props.getFloatNum,
      getDateFormat: this.props.getDateFormat,
      handleSum: this.handleSum,
    };
  };
  /**   获取上传控件的props   */
  getUploadProps = () => {
    return {
      disabled: !this.props.enabled, /*   是否可用   */
      style: {display: commonUtils.convertBooleanToDisplayBlock(this.isUploadShow)}, /*   是否显示   */
    };
  };
  /**   获取查看控件的props   */
  getLookProps = () => {
    return {
      disabled: !this.props.enabled, /*   是否可用   */
      style: {display: commonUtils.convertBooleanToDisplayBlock(this.isLookShow)}, /*   是否显示   */
      onClick: this.handleLookRow, /*   点击事件   */
    };
  };
  /**   获取添加控件的props   */
  getAddProps = () => {
    return {
      disabled: !this.props.enabled, /*   是否可用   */
      style: {display: commonUtils.convertBooleanToDisplayBlock(this.isAddShow)}, /*   是否显示   */
      onClick: this.handleAddRow, /*   点击事件   */
    };
  };

  /**   获取删除控件的props   */
  getDelProps = () => {
    return {
      disabled: !this.props.enabled, /*   是否可用   */
      style: {display: commonUtils.convertBooleanToDisplayBlock(this.isDelShow)}, /*   是否显示   */
      className: styles.del, /*   样式名   */
      onClick: this.handleDelRow, /*   点击事件   */
    };
  };

  handleSearch = (selectedKeys, confirm) => {
    confirm();
    this.setState({searchText: selectedKeys[0]});
  }

  handleReset = (clearFilters) => {
    clearFilters();
    this.setState({searchText: ''});
  }


  /** 修改时求和列 */
  handleSum = (sName) => {
    let dSum = 0;
    const {dataSource, totalData} = this.state;
    if (commonUtils.isNotEmptyArr(dataSource)) {
      dataSource.forEach((item) => {
        dSum += commonUtils.convertStrToNumber0(item[sName]);
      });
      if (commonUtils.isEmptyArr(totalData)) {
        totalData.push({});
      }
      if (sName.substring(sName.length - 5, sName.length).toLowerCase() === 'Price'.toLowerCase()) {
        totalData[0][sName] = dSum;
      } else {
        totalData[0][sName] = dSum;
      }
      totalData[0].bSum = true;
      totalData[0].key = '0000';
      this.setState({totalData});
    }
  }

  /** 求和所有列 */
  handleSumAllColumn = (config, dataSource) => {
    const tableDataTotal = {};
    if (commonUtils.isNotEmptyObject(config) && commonUtils.isNotEmptyArr(dataSource)) {
      const sumConfig = config.gdsconfigformslave.filter(item => item.sName !== '' && item.bVisible && item.bSum);
      if (commonUtils.isNotEmptyArr(sumConfig)) {
        dataSource.forEach((tableDataRow) => {
          sumConfig.forEach((sumItem) => {
            if (tableDataRow.handleType !== 'del') {
              if (sumItem.sName.substring(sumItem.sName.length - 5, sumItem.sName.length).toLowerCase() === 'Price'.toLowerCase()) {
                tableDataTotal[sumItem.sName] = commonUtils.convertToNum(tableDataTotal[sumItem.sName]) +
                  commonUtils.convertToNum(tableDataRow[sumItem.sName]);
              } else {
                tableDataTotal[sumItem.sName] = commonUtils.convertToNum(tableDataTotal[sumItem.sName]) +
                  commonUtils.convertToNum(tableDataRow[sumItem.sName]);
              }
            }
          });
        });
        tableDataTotal.bSum = true;
        tableDataTotal.key = '0000';
        this.setState({totalData: [tableDataTotal]});
      }
    }
  }

  /**   查看行   */
  handleLookRow = () => {
    this.props.onLookRow(this.props.name);
  };
  /**   添加行   */
  handleAddRow = () => {
    this.props.onAddRow(this.props.name);
  };

  /**   删除行   */
  handleDelRow = () => {
    if (this.props.onDelRow(this.props.name)) {
      this.handleSumAllColumn(this.props.config, this.state.dataSource);
    }
  };

  /**   查找控件名是否存在   */
  findIsExistByControlName = (props, controlName) => {
    /*   返回值声明   */
    let ret = false;
    /*   查询控件名是否存在   */
    if (commonUtils.isNotEmptyArr(props.config) && commonUtils.isNotEmptyArr(props.config.gdsconfigformslave) && commonUtils.isNotEmptyStr(controlName)) {
      const controlConfig = props.config.gdsconfigformslave.filter(item => item.sControlName === controlName);
      ret = commonUtils.isNotEmptyArr(controlConfig) && commonUtils.converStrToBoolean(controlConfig[0].bVisible);
    }
    /*   返回值   */
    return ret;
  };

  /**   绑定showType控件   */
  bindShowType = (text, record, sName) => {
    /*   如果从表没有数据就返回一个默认的input text,不返回showType了   */
    if (record.bSum) { /*   从表无数据   */
      const inputProps = {
        disabled: true,
        value: record[sName],
      };
      return (<Input {...inputProps} />);
    } else { /*   从表有数据   */
      return (<ShowTypeNew {...this.getShowTypeProps(text, record, sName)} />);
    }
  };

  /**   willProps赋值   */
  assignmentWillProps = (props) => {
    const {
      dataSource, totalData, selectedRowKeys, enabled, filteredValue, headerColumn, previewImage, previewVisible,
    } = this.state;
    const stateValue = {};

    /*   表头信息(数据类型:数组对象)   */
    if (commonUtils.isEmptyArr(this.headerColumn) && commonUtils.isNotEmptyArr(props.headerColumn)) {
      this.headerColumn = [...props.headerColumn];
      /*   showType附加于表格中   */
      for (const child of this.headerColumn) {
        child.render = (text, record) => this.bindShowType(text, record, child.dataIndex);
      }
    }
    /*   table表头信息(数据类型:数组对象)   */
    if ((commonUtils.isEmptyArr(this.tableColumn) && commonUtils.isNotEmptyArr(this.headerColumn)) || (enabled !== props.enabled)) {
      this.tableColumn = this.getTableColumn(this.headerColumn, 'filter', props);
    }

    /*   table表头信息(数据类型:数组对象)   */
    if (commonUtils.isEmptyArr(this.tableTotalColumn) && commonUtils.isNotEmptyArr(this.headerColumn)) {
      this.tableTotalColumn = this.getTableColumn(this.headerColumn, '', props);
    }

    /*   表格宽度统计值(数据格式:整形)   */
    if (commonUtils.isNotEmptyArr(this.headerColumn)) {
      this.scrollX = this.countScrollX(this.headerColumn);
    }
    /*   窗体Id(数据格式:字符串)   */
    if (commonUtils.isEmptyStr(this.formId)) {
      this.formId = props.formId;
    }
    /*   主表Id(数据格式:字符串)   */
    if (commonUtils.isEmptyStr(this.sId)) {
      this.sId = props.sId;
    }

    /*   是否显示上传控件(数据格式:布尔)   */
    this.isUploadShow = this.findIsExistByControlName(props, 'btnUpload');
    /*   是否显示查看控件(数据格式:布尔)   */
    this.isLookShow = this.findIsExistByControlName(props, 'btnLook');
    /*   是否显示新增控件(数据格式:布尔)   */
    this.isAddShow = this.findIsExistByControlName(props, 'btnAdd');
    /*   是否显示删除控件(数据格式:布尔)   */
    this.isDelShow = this.findIsExistByControlName(props, 'btnDel');
    // /*   上传后执行函数(数据格式:函数)   */
    // this.onUploadChange = props.onUploadChange;

    if (props.data !== undefined && JSON.stringify(dataSource) !== JSON.stringify(props.data)) { // commonUtils.isNotEmptyArr(props.data) 不能用函数不然新增时置空后不能更新数据
      stateValue.dataSource = [...props.data];
    }
    if (props.headerColumn !== undefined && JSON.stringify(headerColumn) !== JSON.stringify(props.headerColumn)) { // commonUtils.isNotEmptyArr(props.data) 不能用函数不然新增时置空后不能更新数据
      stateValue.headerColumn = [...props.headerColumn];
    }
    /* 合计行数据 *//*   数据(数据格式:数组对象)   */
    if (props.totalData !== undefined && JSON.stringify(totalData) !== JSON.stringify(props.totalData) && !this.props.enabled) { // 要用this. this.props.enabled
      stateValue.totalData = [...props.totalData];
      if (commonUtils.isEmptyArr(stateValue.totalData)) {
        stateValue.totalData.push({});
      }
      stateValue.totalData[0].bSum = true;
      stateValue.totalData[0].key = '0000';
    }

    if (props.selectedRowKeys !== undefined && JSON.stringify(selectedRowKeys) !== JSON.stringify(props.selectedRowKeys)) {
      stateValue.selectedRowKeys = [...props.selectedRowKeys];
    }

    if (JSON.stringify(filteredValue) !== JSON.stringify(props.filteredValue)) {
      stateValue.filteredValue = props.filteredValue !== undefined ? [...props.filteredValue] : [];
      if (commonUtils.isNotEmptyArr(this.tableColumn)) {
        this.tableColumn[0].filteredValue = stateValue.filteredValue;
      }
    }

    if (enabled !== props.enabled) {
      stateValue.enabled = props.enabled;
      if (props.enabled) {
        this.handleSumAllColumn(props.config, props.data);
      }
    }
    if (previewImage !== props.previewImage) {
      stateValue.previewImage = props.previewImage;
    }
    if (previewVisible !== props.previewVisible) {
      stateValue.previewVisible = props.previewVisible;
    }
    this.setState(stateValue);
  };

  /**   合并表头   */
  mergeTableColumn = (title, column, tableColumn, index) => {
    /*   '-'之前的内容是父表头   */
    const parentTitle = title.substring(0, index);
    /*   '-'之后的内容是子表头   */
    const childTitle = title.substring(index + 1, title.length);
    /*   把原有表头都替换成子表头   */
    column.title = childTitle;
    /*   查看父表头是否已经添加   */
    const parentObj = tableColumn.filter(item => item.title === parentTitle);
    /*   [{title:1-1},{title:1-2}]变成[{title:1,children:[{title:1},{title:2}]}]   */
    if (commonUtils.isEmptyObject(parentObj)) { /*   父表头未添加   */
      tableColumn.push({
        title: parentTitle,
        children: [column],
      });
    } else { /*   父表头已添加   */
      parentObj[0].children.push(column);
    }
  }

  /**   处理选择行发生改变   */
  handleSelectRowChange = (selectedRowKeys) => {
    this.props.onSelectRowChange(this.props.name, selectedRowKeys);
  };

  /**   计算表格总宽度   */
  countScrollX = (headerColumn) => {
    /*   初始值为37(那个checkbox的宽度)   */
    let scrollX = 37;
    /*   遍历每一个表头配置   */
    for (const each of headerColumn) {
      /*   没给宽度的默认120宽度   */
      const iWidth = each.width === 0 ? 120 : each.width;
      /*   累加宽度   */
      scrollX += iWidth;
    }
    /*   返回值   */
    return scrollX;
  };

  /** 合计滚动 */
  handleTotalScroll = () => {
    if (this.state.totalData.length > 0) {
      const {currentPane, panes} = this.props.app;
      const index = panes.indexOf(currentPane);
      /* 当前页签 */
      const currentTab = document.getElementById('tabs').getElementsByClassName('ant-tabs-content-no-animated')[0].children[index];
      if (!commonUtils.isEmpty(currentTab)) {
        const antTab = currentTab.getElementsByClassName('ant-tabs-content-animated');
        const childTab = commonUtils.isNotEmptyArr(antTab) ? antTab[0].children : {};
        const indexSlave = Object.keys(childTab).findIndex(item => childTab[item].getAttribute('aria-hidden') === 'false');
        /* 从表当前页签 */
        if (indexSlave > -1) {
          const topTable = childTab[indexSlave].getElementsByClassName('ant-table-body')[0];
          const botTable = childTab[indexSlave].getElementsByClassName('ant-table-body')[1];
          if (botTable !== undefined) {
            botTable.onscroll = () => {
              topTable.scrollLeft = botTable.scrollLeft;
            };
          }
        }
      }
    }
  };
  /**   关闭弹窗   */
  handleModalCancel = () => {
    this.props.onModalCancel();
  };
  /** 上传文件改变时的状态 */
  handleUploadChange = (info) => {
    this.props.onUploadChange(info, this.props.name);
  };

  /**修改表头的样式*/
  adaptTableHeader = (tablePropsOld) => {
    for (let i in tablePropsOld.columns) {
      tablePropsOld.columns[i]['className'] = 'column-money';
      if (window.location.pathname !== '/commonBill'
        &&window.location.pathname !== '/workOrderNew'
        &&window.location.pathname !== '/processCard'
        &&window.location.pathname !== '/purpurchasecheckingmaster'
        &&window.location.pathname !== '/opsoutsideprocessmaster'
        &&window.location.pathname !== '/mitmaterialscheckmaster'
        &&window.location.pathname !== '/pitproductcheckmaster'
        &&window.location.pathname !== '/commonClassify'
        &&window.location.pathname !== '/commonClassify'
        &&window.location.pathname !== '/elecustomer'
        &&window.location.pathname !== '/elesupply'
        &&window.location.pathname !== '/elematerials'
        &&window.location.pathname !== '/eleprocess'
        &&window.location.pathname !== '/siscommonstyle'
        &&window.location.pathname !== '/eleteamInfo'
        &&window.location.pathname !== '/elecheckmodel'
        &&window.location.pathname !== '/sischeckphase'
        &&window.location.pathname !== '/sftlogininfo'
        &&window.location.pathname !== '/elecustomer'
      ) {
        tablePropsOld.columns[i].render = (text) => <div style={{
          border: '#d9d9d9 solid 1.5px',
          display: 'block',
          textAlign: 'center',
          margin: 5,
          borderRadius: 3,
          minHeight: 25
        }}>{text}</div>

      }
    }
    return tablePropsOld;
  };
  /**修改表内数据*/
  adaptTableTotalProps = (totalProps) => {
    var tableTotalProps = [];
    for (let i in totalProps.columns) {
      if (totalProps.columns[i] !== null) {
        var adaptString = totalProps.columns[i].dataIndex;

        if (totalProps.dataSource[0] !== undefined) {
          if (totalProps.dataSource[0][adaptString]) {
            tableTotalProps.push({name: totalProps.columns[i].title, value: totalProps.dataSource[0][adaptString]})
          }
        }
      }
    }

    return tableTotalProps

  }

  /**   渲染   */
  render() {
    /*   获取upload的props   */
    const uploadProps = this.getUploadProps();
    const {previewVisible, previewImage} = this.state;
    const {formId} = this.props;
    const {token} = this.props.app;
    const divProps = {
      action: `${commonConfig.server_host}file/upload?sModelsId=${formId}&token=${token}`,
      onChange: this.handleUploadChange,
      accept: 'image/*',
      showUploadList: false,
      beforeUpload: () => {
        /* 查看时不可上传 */
        if (!this.props.enabled) return false;
      },
    };
    /*   获取look的props   */
    const lookProps = this.getLookProps();

    /*   获取add的props   */
    const addProps = this.getAddProps();

    /*   获取del的props   */
    const delProps = this.getDelProps();

    /*   获取table中的props   */
    const tablePropsOld = this.getTableProps();


    ////////
    /////用tag实现表格里面的东西突出显示
    const tableProps = this.adaptTableHeader(tablePropsOld);


    /*   获取合计table中的props   */
    const tableTotalPropsOld = this.getTableTotalProps();
    const tableTotalProps = this.adaptTableTotalProps(tableTotalPropsOld);

    /*   页面输出   */
    return (
      <FormItem className={styles.subForm}>
        <div>
          <div className={styles.tableOption}>
            {
              this.props.name === 'picFile' ?
                <Upload {...divProps}>
                  <Button {...uploadProps}>
                    <Icon type="upload"/> 上传
                  </Button>
                </Upload>
                : null}
            <Button {...lookProps}>查看</Button>
            <Button {...addProps}>增行</Button>
            <Button {...delProps} >删行</Button>
          </div>
          <div id="staticEditTable">
            <div className="topTable">
              <Table {...tableProps}/>
            </div>
            {
              this.state.totalData.length > 0 ?
                <div style={{backgroundColor: '#d9d9d9', display: 'flex'}}>
                  {
                    tableTotalProps.map(v => <div key={v}
                                                  style={{flex: 1, fontWeight: 30, fontSize: 16}}>总{v.name}:<span
                      style={{fontSize: 14, color: '#00c1de'}}>{v.value}</span></div>)
                  }
                </div>
                : null}
          </div>
          <Modal
            visible={previewVisible}
            footer={null}
            onCancel={this.handleModalCancel}
            width={1000}
          >
            <img alt="example" style={{width: '100%'}} src={previewImage}/>
          </Modal>
        </div>
      </FormItem>
    );
  }
}



/*
'/commonBill'
'/workOrderNew'
'/processCard'
'/purpurchasecheckingmaster'
'/opsoutsideprocessmaster'
'/mitmaterialscheckmaster'
'/pitproductcheckmaster'
'/commonClassify'
'/commonClassify'
'/elecustomer'
'/elesupply'
'/elematerials'
'/eleprocess'
'/siscommonstyle'
'/eleteamInfo'
'/elecheckmodel'
'/sischeckphase'
'/sftlogininfo'
'/elecustomer'
*/
